/**
 * 
 */
package com.planner.core.service.core.algorithm.dijkstra;

import java.util.ArrayList;
import java.util.List;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.springframework.beans.factory.annotation.Required;

import com.planner.core.algorithm.dijkstra.model.Edge;
import com.planner.core.service.core.algorithm.AbstractAlgorithmService;
import com.planner.core.service.core.stop.StopService;
import com.planner.core.vo.GraphNode;
import com.planner.core.vo.GraphNodeCode;

/**
 * @author Sangharsh
 * 
 */
public class DijkstraAlgorithmServiceImpl extends AbstractAlgorithmService {

	private static final Log LOG = LogFactory
			.getLog(DijkstraAlgorithmServiceImpl.class);
	private StopService stopService;

	private List<GraphNode> nodes;
	private List<Edge> edges;

	public DijkstraAlgorithmServiceImpl() {
		super();
	}

	private void addLane(String fromCode, String toCode) {
		GraphNode from = stopService.getNode(fromCode);
		GraphNode to = stopService.getNode(toCode);
		Edge laneUp = new Edge(from.getName() + " To " + to.getName(), from, to, 1);
		Edge laneDown = new Edge(to.getName() + " To " + from.getName(), to, from, 1);
		edges.add(laneUp);
		edges.add(laneDown);
	}

	@Override
	public void setUp() {
		nodes = stopService.getAllNodes();
		edges = new ArrayList<Edge>();
		setUpYellowLine();
		setUpVioletLine();
	}
	private void setUpVioletLine(){
		addLane(GraphNodeCode.BADARPUR, GraphNodeCode.TUGHLAKABAD);
		addLane(GraphNodeCode.TUGHLAKABAD, GraphNodeCode.MOHAN_ESTATE);
		addLane(GraphNodeCode.MOHAN_ESTATE, GraphNodeCode.SARITA_VIHAR);
		addLane(GraphNodeCode.SARITA_VIHAR, GraphNodeCode.JASOLA_APOLLO);
		addLane(GraphNodeCode.JASOLA_APOLLO, GraphNodeCode.OKHLA);
		addLane(GraphNodeCode.OKHLA, GraphNodeCode.GOVIND_PURI);
		addLane(GraphNodeCode.GOVIND_PURI, GraphNodeCode.KALKAJI_MANDIR);
		addLane(GraphNodeCode.KALKAJI_MANDIR, GraphNodeCode.NEHRU_PLACE);
		addLane(GraphNodeCode.NEHRU_PLACE, GraphNodeCode.KAILASH_COLONY);
		addLane(GraphNodeCode.KAILASH_COLONY, GraphNodeCode.MOOLCHAND);
		addLane(GraphNodeCode.MOOLCHAND, GraphNodeCode.LAJPAT_NAGAR);
		addLane(GraphNodeCode.LAJPAT_NAGAR, GraphNodeCode.JANGPURA);
		addLane(GraphNodeCode.JANGPURA, GraphNodeCode.JLN_STADIUM);
		addLane(GraphNodeCode.JLN_STADIUM, GraphNodeCode.KHAN_MARKET);
		addLane(GraphNodeCode.KHAN_MARKET, GraphNodeCode.CENTRAL_SECRETARIAT);
	} 
	/**
	 * 
	 */
	private void setUpYellowLine() {
		addLane(GraphNodeCode.HUDA_CITY_CENTRE, GraphNodeCode.IFFCO_CHOWK);
		addLane(GraphNodeCode.IFFCO_CHOWK, GraphNodeCode.M_G_ROAD);
		addLane(GraphNodeCode.M_G_ROAD, GraphNodeCode.SIKANDARPUR);
		addLane(GraphNodeCode.SIKANDARPUR, GraphNodeCode.GURU_DRONACHARYA);
		addLane(GraphNodeCode.GURU_DRONACHARYA, GraphNodeCode.ARJANGARH);
		addLane(GraphNodeCode.ARJANGARH, GraphNodeCode.GHITORNI);
		addLane(GraphNodeCode.GHITORNI, GraphNodeCode.SULTANPUR);
		addLane(GraphNodeCode.QUTAB_MINAR, GraphNodeCode.SAKET);
		addLane(GraphNodeCode.SAKET, GraphNodeCode.MALVIYA_NAGAR);
		addLane(GraphNodeCode.MALVIYA_NAGAR, GraphNodeCode.HAUZ_KHAS);
		addLane(GraphNodeCode.HAUZ_KHAS, GraphNodeCode.GREEN_PARK);
		addLane(GraphNodeCode.GREEN_PARK, GraphNodeCode.AIIMS);
		addLane(GraphNodeCode.AIIMS, GraphNodeCode.INA);
		addLane(GraphNodeCode.INA, GraphNodeCode.JORBAGH);
		addLane(GraphNodeCode.JORBAGH, GraphNodeCode.RACE_COURSE);
		addLane(GraphNodeCode.RACE_COURSE,GraphNodeCode.UDYOG_BHAWAN);
		addLane(GraphNodeCode.UDYOG_BHAWAN,GraphNodeCode.CENTRAL_SECRETARIAT);
		addLane(GraphNodeCode.CENTRAL_SECRETARIAT,GraphNodeCode.PATEL_CHOWK);
		addLane(GraphNodeCode.PATEL_CHOWK,GraphNodeCode.RAJIV_CHOWK);
		addLane(GraphNodeCode.RAJIV_CHOWK,GraphNodeCode.NEW_DELHI);
		addLane(GraphNodeCode.NEW_DELHI,GraphNodeCode.CHAWRI_BAZAR);
		addLane(GraphNodeCode.CHAWRI_BAZAR,GraphNodeCode.CHANDNI_CHOWK);
		addLane(GraphNodeCode.CHANDNI_CHOWK,GraphNodeCode.KASHMERE_GATE);
		addLane(GraphNodeCode.KASHMERE_GATE,GraphNodeCode.CIVIL_LINES);
		addLane(GraphNodeCode.CIVIL_LINES,GraphNodeCode.VIDHAN_SABHA);
		addLane(GraphNodeCode.VIDHAN_SABHA,GraphNodeCode.VISHWAVIDYALAYA);
		addLane(GraphNodeCode.VISHWAVIDYALAYA,GraphNodeCode.GTB_NAGAR);
		addLane(GraphNodeCode.GTB_NAGAR,GraphNodeCode.MODEL_TOWN);
		addLane(GraphNodeCode.MODEL_TOWN,GraphNodeCode.AZADPUR);
		addLane(GraphNodeCode.AZADPUR,GraphNodeCode.ADARSH_NAGAR);
		addLane(GraphNodeCode.ADARSH_NAGAR,GraphNodeCode.JAHANGIRPURI);
	}

	/**
	 * @param stopService
	 *            the stopService to set
	 */
	@Required
	public void setStopService(StopService stopService) {
		this.stopService = stopService;
	}

	/**
	 * @return the nodes
	 */
	public List<GraphNode> getNodes() {
		return nodes;
	}

	/**
	 * @return the edges
	 */
	public List<Edge> getEdges() {
		return edges;
	}

}
